package com.umeox.ota.ui.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.lifecycle.ViewModelProviders;

import com.umeox.ota.OtaResultFragmentBinding;
import com.umeox.ota.R;
import com.umeox.ota.mvvm.viewModel.NoticeViewModel;
import com.umeox.ota.utils.ThemeColor;
import com.umeox.ota.utils.ViewUitls;

/**
 * @author fighter_lee
 * @date 2017/8/23
 */

public class OtaResultFragment extends BaseFragment<OtaResultFragmentBinding, NoticeViewModel> implements View.OnClickListener, View.OnFocusChangeListener {

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mBinding.setViewmodel(mViewModel);
        mBinding.btnClickOk.setOnClickListener(this);
        mBinding.btnClickOk.setFocusable(true);
        mBinding.btnClickOk.setOnFocusChangeListener(this);
        mBinding.btnClickOk.requestFocus();
        return mBinding.getRoot();
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        mBinding.btnClickOk.setOnFocusChangeListener(this);
    }

    @Override
    public void setData(Object data) {

    }

    @Override
    protected int genLayoutId(Bundle savedInstanceState) {
        return R.layout.fragment_ota_result;
    }

    @Override
    protected void genViewModel() {
        mViewModel = ViewModelProviders.of(getActivity(), mViewModelFactory).get(NoticeViewModel.class);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_click_ok:
                getActivity().finish();
                break;
            default:
                break;
        }
    }

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            v.setBackgroundColor(ViewUitls.darkenColor(ThemeColor.textColorPrimary,0.6f));
        } else {
            v.setBackgroundColor(ThemeColor.textColorPrimary);
        }
    }
}
